<?php
//域名配置

$env_hosts = [
    'local'      => ['aireader.com'],
    'develop'    => ['www.laravel.dev'],
    'test'       => ['www.laravel.test'],
    'production' => ['www.laravel.com'],
];

//热更新只需要在修改.env 配置后删除 bootstrap/cache 下的缓存文件即可
//环境处理
if (!$app->runningInConsole()) {//HTTP形式
    if (empty($_SERVER['HTTP_HOST'])) {
        die('[error] no host');
    }
    foreach ($env_hosts as $env => $hosts) {
        if (in_array($_SERVER['HTTP_HOST'], $hosts)) {
            $app_env = $env;
            break;
        }
    }
} else {//其它形式
    $app_env = $app->detectEnvironment(function () {
        return 'production';
    });
}
if (empty($app_env) || empty($env_hosts[$app_env])) {
    die('[error] no environment');
}
//写入环境配置
$app->loadEnvironmentFrom($app_env . '.env')
    ->useEnvironmentPath(base_path('env'));